<%@page import="cn.util.Const"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>首页</title>
<link href="<%=Const.ROOT %>admin/css/bootstrap.min.css" rel="stylesheet">
<link href="<%=Const.ROOT %>admin/css/materialdesignicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="<%=Const.ROOT %>admin/js/jconfirm/jquery-confirm.min.css">
<link href="<%=Const.ROOT %>admin/css/style.min.css" rel="stylesheet">
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">

    <%@include file="inc/aside.jsp" %>
    <%@include file="inc/header.jsp" %>
    
    
    <!--页面主要内容-->
    <main class="lyear-layout-content">
      <div class="container-fluid">
        
        <div class="row">
          <div class="col-lg-12">
            <div class="card">
              <div class="card-toolbar clearfix">
                <form class="pull-right search-bar" method="post" action="<%=Const.ROOT %>orders/admin/list" role="form" id="searchForm">
                  <input type="hidden" name="pageNo" id="pageNo"/>
                  <div class="input-group">
                    <input type="text" class="form-control" value="${ordersno}" name="ordersno" placeholder="请输入订单编号">
					<div class="input-group-btn">
					  <input type="hidden" name="search_field" id="search-field" value="title">
					  <button class="btn btn-default dropdown-toggle" id="search-btn" type="submit" aria-haspopup="true" aria-expanded="false">
						<i class="mdi mdi-search-web"></i> 搜索
					  </button>
					</div>
                  </div>
                </form>
               
              </div>
              <div class="card-body">
                
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr>
                        <th>编号</th>
                        <th>客户</th>
                        <th>联系方式</th>
                        <th>总价</th>
                        <th>订单时间</th>
                        <th>状态</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                    <c:forEach items="${list }" var="v" varStatus="st">
                      <tr>
                        <td>${v.orderno }</td>
                        <td>${v.users.name }</td>
                        <td>${v.users.address }[${v.users.phone }]</td>
                        <td>${v.price }</td>
                        <td>${v.optime }</td>
                        <td>${v.status }</td>
                        <td>
                          <div class="btn-group">
                          	<c:if test="${v.status=='未发货' }">
                            	<button class="btn btn-xs btn-primary" onclick="fahuo(${v.id})">发货</button>
                          	</c:if>
                          	<c:if test="${v.status=='申请退货' }">
                            	<button class="btn btn-xs btn-primary" onclick="tongyi(${v.id})">同意</button>
                          	</c:if>
                            <button class="btn btn-xs btn-warning" onclick="view(${v.id})">查看</button>
                            <button class="btn btn-xs btn-danger" onclick="del(${v.id})">删除</button>
                          </div>
                        </td>
                      </tr>
                      </c:forEach>
                    </tbody>
                  </table>
                </div>
                <ul class="pager">
                  <li><a href="javascript:goPage(${pageBean.prevPage })">上一页</a></li>
                  <li><a href="javascript:goPage(${pageBean.nextPage })">下一页</a></li>
                </ul>
              </div>
            </div>
          </div>
        </div>
	  </div>
    </main>
    <!--End 页面主要内容-->
  </div>
</div>

<!--新增-->
 <div class="modal fade" id="viewModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
	<form class="form-horizontal" action="" method="post">
	<div class="modal-content">
	  <div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
		<h4 class="modal-title">商品列表</h4>
	  </div>
	  <div class="modal-body">
		<table class="table">
			<tr>
				<td>编号</td>
				<td>商品名称</td>
				<td>数量</td>
				<td>小计</td>
			</tr>
			<tbody id="details">
				
			</tbody>
		</table>
	  </div>
	  <div class="modal-footer">
		<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
	  </div>
	</div>
	</form>
  </div>
</div>


<script type="text/javascript" src="<%=Const.ROOT %>admin/js/jquery.min.js"></script>
<script type="text/javascript" src="<%=Const.ROOT %>admin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="<%=Const.ROOT %>admin/js/perfect-scrollbar.min.js"></script>
<script src="<%=Const.ROOT %>admin/js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript" src="<%=Const.ROOT %>admin/js/main.min.js"></script>
<script type="text/javascript" src="<%=Const.ROOT %>admin/js/ajaxfileupload.js"></script>

<script type="text/javascript">
$(function(){
	//ajax请求获取所有分类，json填充到下拉
	$.getJSON("<%=Const.ROOT %>kind/jsonlist",function(data){
		$("#kid1").html("<option value=''>请选择商品分类</option>");
		$("#kid2").html("<option value=''>请选择商品分类</option>");
		for(i=0;i<data.length;i++){
			$("#kid1").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
			$("#kid2").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
		}
	});
});

//ajax文件上传
function uploadFile1(){
	 if($("#file1").val()==""){
		  alert("请先选择文件!");
	  }else{
		  $.ajaxFileUpload(
	      {
	          url: '<%=Const.ROOT%>upload', //用于文件上传的服务器端请求地址
	          secureuri: false, //是否需要安全协议，一般设置为false
	          fileElementId: 'file1', //文件上传域的ID
	          success: function (data, status)  //服务器成功响应处理函数
	          {   
	        	  //如果文件上传成功，可以获取到文件名称,给pic隐藏域赋值
	        	  $("#pic1").val($(data).find("body").text());
	        	  alert("上传成功，请点击保存！");
	          },
	          error: function (data, status, e)//服务器响应失败处理函数
	          {
	              alert("上传失败!");
	          }
	      });
	  }
  return false;
}

//ajax文件上传
function uploadFile2(){
	 if($("#file2").val()==""){
		  alert("请先选择文件!");
	  }else{
		  $.ajaxFileUpload(
	      {
	          url: '<%=Const.ROOT%>upload', //用于文件上传的服务器端请求地址
	          secureuri: false, //是否需要安全协议，一般设置为false
	          fileElementId: 'file2', //文件上传域的ID
	          success: function (data, status)  //服务器成功响应处理函数
	          {   
	        	  //如果文件上传成功，可以获取到文件名称,给pic隐藏域赋值
	        	  $("#pic2").val($(data).find("body").text());
	        	  alert("上传成功，请点击保存！");
	          },
	          error: function (data, status, e)//服务器响应失败处理函数
	          {
	              alert("上传失败!");
	          }
	      });
	  }
  return false;
}

function add(){
	$("#addModal").modal("show");
}
function update(id){
	$.getJSON("<%=Const.ROOT %>goods/json",{"id":id},function(data){
		//ajax
		$("#updateModal #v_id").val(id);
		$("#updateModal #kid2").val(data.kid);
		$("#updateModal #v_name").val(data.name);
		$("#updateModal #pic2").val(data.pic);
		$("#updateModal #v_price").val(data.price);
		$("#updateModal #v_kucun").val(data.kucun);
		$("#updateModal #v_content").val(data.content);
		$("#updateModal").modal("show");
	});
}

function view(id){
	$.getJSON("<%=Const.ROOT %>orders/admin/detail/"+id,function(data){
		$("#details").html("");
		for(i=0;i<data.length;i++){
			var od=data[i];
			$("#details").append("<tr>"+
					"<td>"+(i+1)+"</td>"+
					"<td>"+od.goods.name+"</td>"+
					"<td>"+od.quantity+"</td>"+
					"<td>"+od.price+"</td>"+
				"</tr>");
		}
		$("#viewModal").modal("show");
	});
}

function fahuo(id){
	$.confirm({
		title: '提示信息',
		content: '是否发货?',
		type: 'orange',
		typeAnimated: false,
		buttons: {
			omg: {
				text: '确定',
				btnClass: 'btn-orange',
				action: function(){
					location="<%=Const.ROOT %>orders/admin/update?id="+id+"&status=已发货";
				}
			},
			close: {
				text: '取消',
			}
		}
	});
}

function tongyi(id){
	$.confirm({
		title: '提示信息',
		content: '是否同意退货?',
		type: 'orange',
		typeAnimated: false,
		buttons: {
			omg: {
				text: '确定',
				btnClass: 'btn-orange',
				action: function(){
					location="<%=Const.ROOT %>orders/admin/update?id="+id+"&status=已退货";
				}
			},
			close: {
				text: '取消',
			}
		}
	});
}
function del(id){
	$.confirm({
		title: '提示信息',
		content: '是否删除?',
		type: 'orange',
		typeAnimated: false,
		buttons: {
			omg: {
				text: '确定',
				btnClass: 'btn-orange',
				action: function(){
					location.href="<%=Const.ROOT %>orders/admin/delete?id="+id;
				}
			},
			close: {
				text: '取消',
			}
		}
	});
}
function goPage(pageNo){
	$("#pageNo").val(pageNo);
	$("#searchForm").submit();
}
</script>
</body>
</html>